package com.pro.util.generator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.databind.deser.Deserializers.Base;

public class ClassBean {
	private static String TAB = "\t";
	private static String space = " ";
	private List<ColumnBean> columnList;
	private List<Method> methodList;
	private String className;
	private String packageName;

	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public List<ColumnBean> getColumnList() {
		return columnList;
	}

	private Map<String, String> typeList = new HashMap<String, String>();

	public Map<String, String> getTypeList() {
		return typeList;
	}

	// public void setTypeList(List<String> typeList) {
	// this.typeList = typeList;
	// }
	public void setColumnList(List<ColumnBean> columnList) {
		for (ColumnBean col : columnList) {
			String type = col.getJavaType();
			switch (type) {
			case "Date":
				typeList.put(type,"java.util.Date");
				break;
			default:
				break;
			}
		}
		this.columnList = columnList;
	}

	public List<Method> getMethodList() {
		return methodList;
	}

	public void setMethodList(List<Method> methodList) {
		this.methodList = methodList;
	}

	private void initImport(StringBuffer sb) {
		Iterator<String> iterator = typeList.keySet().iterator();
		while(iterator.hasNext()){
			String key = iterator.next();
			String value = typeList.get(key);
			sb.append("import" + BaseClassPro.SPACE + value + ";\r\n");
		}
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("package" + BaseClassPro.SPACE + this.getPackageName()
				+ BaseClassPro.SPLIT + "\r\n");
		initImport(sb);
		sb.append(BaseClassPro.PUBLIC + BaseClassPro.SPACE + "class"
				+ BaseClassPro.SPACE + this.getClassName()
				+ BaseClassPro.LEFT_K + "\r\n\t");
		for (ColumnBean col : columnList) {
			sb.append(col.toString());
		}
		sb.append(BaseClassPro.RIGHT_K);
		return sb.toString();
	}

	// public static void main(String[] args) {
	//
	// }

}
